package socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/*
* 服务端
* 1.创建ServerSocket对象,指定端口号
* 2.调用accept方法,等待客户端连接
* 3.接收客户端发送的信息
* */
public class Server {
    private ServerSocket serverSocket;

    public Server(){
        try {
            System.out.println("正在启动服务器");
            serverSocket = new ServerSocket(8088);
            System.out.println("服务器启动完毕");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void start(){
        try {
            System.out.println("等待客户端连接...");
            Socket socket = serverSocket.accept();//接收客户端连接,返回一个新的socket对象
            System.out.println("一个客户端连接了");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        Server server = new Server();
        server.start();
    }

}
